package com.randy.recyclerviews.modal;

import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;

import com.randy.recyclerviews.R;
import com.randy.recyclerviews.adapter.UniversalAdapter;


/**
 * @author xudong
 * @since 2017/3/10
 */

public class SpaceItemModel extends UniversalAdapter.AbstractModel<SpaceItemModel.ViewHolder> {
    private final int height;

    public SpaceItemModel(int height) {
        this.height = height > 0 ? height : 1;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.layout_common_space;
    }

    @Override
    public void bindData(@NonNull ViewHolder holder) {
        ViewGroup.MarginLayoutParams layoutParams =
                (ViewGroup.MarginLayoutParams) holder.itemView.getLayoutParams();
        layoutParams.height = height;
        holder.itemView.setLayoutParams(layoutParams);
    }

    @NonNull
    @Override
    public UniversalAdapter.IViewHolderCreator<ViewHolder> getViewHolderCreator() {
        return new UniversalAdapter.IViewHolderCreator<ViewHolder>() {
            @NonNull
            @Override
            public ViewHolder create(@NonNull View view) {
                return new ViewHolder(view);
            }
        };
    }

    public static class ViewHolder extends UniversalAdapter.ViewHolder {
        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
